package com.stm.bi.web;

import com.stm.bi.dto.query.*;
import com.stm.bi.dto.vo.*;
import com.stm.bi.model.Chart;
import com.stm.bi.model.DatatablePage;
import com.stm.bi.service.PerformanceService;
import com.stm.framework.annotation.Module;
import com.stm.framework.annotation.ReqParam;
import com.stm.framework.annotation.RestApi;
import com.stm.framework.dto.Response;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author liuyx
 * @date 2025/2/13 11:04
 */
@RestController
@RequestMapping("/performance")
@Module("实绩")
public class PerformanceController {
    @Resource
    private PerformanceService performanceService;

    @GetMapping(value = "/shopRanking")
    @RestApi(name = "工作台-门店排名", author = "wsb", idx = 1, permission = "plan:performance:query")
    public Response<Chart<YesterdayVO>> shopRanking(@RequestParam("deptId") @ReqParam(label = "部门ID") Long deptId) {
        return performanceService.shopRanking(deptId);
    }


    @GetMapping(value = "/styleTypeQty")
    @RestApi(name = "工作台-商品类型销售额", author = "wsb", idx = 2, permission = "plan:performance:query")
    public Response<Chart> styleTypeQty(@RequestParam("deptId") @ReqParam(label = "部门ID") Long deptId) {
        return performanceService.styleTypeQty(deptId);
    }


    @GetMapping(value = "/getSalesProIndexChart")
    @RestApi(name = "工作台-销售额过程指标", author = "wsb", idx = 3, permission = "plan:performance:query")
    public Response<Chart<SalesProIndexChartVO>> getSalesProIndexChart(@RequestParam("deptId") @ReqParam(label = "部门ID", required = true) Long deptId){
        return performanceService.getSalesProIndexChart(deptId);
    }

    @GetMapping(value = "/regionalProportionOfCustomers")
    @RestApi(name = "工作台-区域顾客占比", author = "zp", idx = 4, permission = "plan:performance:query")
    public Response<Chart> regionalProportionOfCustomers(RegionalSaleQry regionalSaleQry) {
        return performanceService.regionalProportionOfCustomers(regionalSaleQry);
    }



    @GetMapping(value = "/regionalSaleRank")
    @RestApi(name = "工作台-全国销量排名", author = "zp", idx = 5, permission = "plan:performance:query")
    public Response<Chart> regionalSaleRank(RegionalSaleQry regionalSaleQry) {
        return performanceService.regionalSaleRank(regionalSaleQry);
    }

    @GetMapping(value = "/regionalCustomerRank")
    @RestApi(name = "工作台-全国新老客排名", author = "zp", idx = 6, permission = "plan:performance:query")
    public Response<Chart> regionalCustomerRank(RegionalSaleQry regionalSaleQry) {
        return performanceService.regionalCustomerRank(regionalSaleQry);
    }


    @GetMapping(value = "/regionalProportionOfCustomersToB")
    @RestApi(name = "工作台-ToB区域顾客占比", author = "zp", idx = 7, permission = "plan:performance:query")
    public Response<Chart<RegionalCustomerVO>> regionalProportionOfCustomersToB(RegionalSaleQry regionalSaleQry) {
        return performanceService.regionalProportionOfCustomersToB(regionalSaleQry);
    }

    @GetMapping(value = "/turnoverRankChartToB")
    @RestApi(name = "工作台-全国成交量Top排名", author = "liuyx", idx = 8, permission = "plan:performance:query")
    public Response<Chart> turnoverRankChartToB(RegionalSaleQry regionalSaleQry) {
        return performanceService.turnoverRankChartToB(regionalSaleQry);
    }

    @GetMapping(value = "/bizCustomersRankChartToB")
    @RestApi(name = "工作台-全国新老客Top排名", author = "liuyx", idx = 9, permission = "plan:performance:query")
    public Response<Chart> bizCustomersRankChartToB(RegionalSaleQry regionalSaleQry) {
        return performanceService.bizCustomersRankChartToB(regionalSaleQry);
    }

    @GetMapping(value = "/regionalStyleSales")
    @RestApi(name = "工作台-区域款式销量", author = "zp", idx = 10, permission = "plan:performance:query")
    public Response<RegionalStyleSalesVO> RegionalStyleSales(RegionalSaleQuery regionalSaleQry) {
        return performanceService.regionalStyleSales(regionalSaleQry);
    }

    @GetMapping(value = "/regionalStyleSalesMap")
    @RestApi(name = "工作台-区域款式销量地图", author = "zp", idx = 10, permission = "plan:performance:query")
    public Response<Chart> regionalStyleSalesMap(RegionalSaleQuery regionalSaleQry) {
        return performanceService.regionalStyleSalesMap(regionalSaleQry);
    }

    @GetMapping(value = "/regionalTurnover")
    @RestApi(name = "工作台-ToB区域成交量", author = "zp", idx = 11, permission = "plan:performance:query")
    public Response<RegionalCustomerToBVO> RegionalTurnover(RegionalSaleQuery regionalSaleQry) {
        return performanceService.regionalTurnover(regionalSaleQry);
    }

    @GetMapping(value = "/regionalTurnoverMap")
    @RestApi(name = "工作台-ToB成交量地图", author = "zp", idx = 12, permission = "plan:performance:query")
    public Response<Chart> RegionalTurnoverMap(RegionalSaleQuery regionalSaleQry) {
        return performanceService.regionalTurnoverMap(regionalSaleQry);
    }

    @GetMapping(value = "/salesTrend/lineChart")
    @RestApi(name = "销售推移-折线图", author = "wsb", idx = 13)
    public Response<Chart<List<ValueVO<BigDecimal>>>> salesTrendLineChart(SalesTrendLineChartQuery query) {
        return performanceService.salesTrendLineChart(query);
    }

    @GetMapping(value = "/salesTrend/detailLineChart")
    @RestApi(name = "销售推移-明细折线图", author = "wsb", idx = 14)
    public Response<Chart<List<List<Object>>>> salesTrendDetailLineChart(SalesTrendDetailLineChartQuery query) {
        return performanceService.salesTrendDetailLineChart(query);
    }

    @GetMapping(value = "/salesTrend/table")
    @RestApi(name = "销售推移-推移表", author = "wsb", idx = 15)
    public Response<DatatablePage> salesTrendTable(SalesTrendTableQuery query) {
        return performanceService.salesTrendTable(query);
    }

    @GetMapping(value = "/salesTrend/export")
    @RestApi(name = "销售推移-推移表", author = "wsb", idx = 16)
    public void salesTrendTableExport(HttpServletResponse response, SalesTrendTableQuery query) throws IOException {
        performanceService.salesTrendTableExport(response, query);
    }

    @GetMapping(value = "/lineChartByDeptId")
    @RestApi(name = "业务销售实绩-推移表")
    public Response<Chart> lineChartByDeptId(DeptSalesTrendChartQry qry) {
        return performanceService.lineChartByDeptId(qry);
    }
}
